﻿using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;

using SBPweb.Modules.Modularity;

namespace SBPweb.MediaCenter.Modules.Organizer.WPF.Controls
{

    /// <summary>
    /// Interaction logic for FolderTreeView.xaml
    /// </summary>
    public partial class FolderTreeView : TreeView
    {

        #region Private fields

        private DirectoryInfo rootFolder;
        private IModule parentModule;

        #endregion

        #region Constructor logic

        public FolderTreeView()
        {
            InitializeComponent();
        }

        public FolderTreeView(IModule parentModule, DirectoryInfo rootFolder)
        {
            InitializeComponent();
            this.ParentModule = parentModule;
            this.RootFolder = rootFolder;
        }

        #endregion

        #region Property accessors

        public DirectoryInfo RootFolder
        {
            get
            {
                return rootFolder;
            }
            set
            {
                bool b = rootFolder != value;
                rootFolder = value;
                if (b)
                {
                    PopulateItems();
                }
            }
        }

        public IModule ParentModule
        {
            get
            {
                return parentModule;
            }
            set
            {
                parentModule = value;
            }
        }

        #endregion

        #region Methods

        public void PopulateItems()
        {
            this.Items.Clear();
            foreach (DirectoryInfo dI in rootFolder.GetDirectories())
            {
                this.Items.Add(dI);
            }
        }

        #endregion


    }

}